{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1、数字 → number\n",
    "* Python 数字数据类型用于存储数值\n",
    "* 整型、浮点型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "int"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 整型\n",
    "type(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 浮点型\n",
    "type(10.0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "117\n",
      "83\n",
      "1700\n",
      "5.882352941176471\n",
      "5\n",
      "10000\n",
      "15\n"
     ]
    }
   ],
   "source": [
    "# 算术运算 → 数值计算\n",
    "a = 100\n",
    "b = 17\n",
    "print(a + b) # 加法\n",
    "print(a - b) # 减法\n",
    "print(a * b) # 乘法\n",
    "print(a / b) # 除法 → 得到浮点型\n",
    "print(a // b) # 除法 → 取整数\n",
    "print(a ** 2) # 乘方\n",
    "print(a % b)  # 取余"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2、布尔型\n",
    "* 布尔运算，用于判断结果 → True or False（请注意大小写）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "False\n",
      "True\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 比较运算符 → 数值之间比较\n",
    "print(1>2)   # 大于\n",
    "print(1<2)   # 小于\n",
    "print(1==2)  # 等于\n",
    "print(1!=2)  # 不等于\n",
    "print(1>=2)  # 大于等于\n",
    "print(1<=2)  # 小于等于"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "------\n",
      "True\n",
      "False\n",
      "------\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 逻辑运算符 → 且、或、非\n",
    "print(True and True) \n",
    "print(True and False)\n",
    "print('------')\n",
    "# and：且\n",
    "print(True or False) \n",
    "print(False or False)\n",
    "print('------')\n",
    "# or：或\n",
    "print(not True) \n",
    "print(not False)\n",
    "# not：非"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "True\n",
      "11\n"
     ]
    }
   ],
   "source": [
    "# 本质上，True = 1，False = 0\n",
    "print(True == 1)\n",
    "print(False == 0)\n",
    "print(True + 10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3、字符串\n",
    "* 字符串是 Python 中最常用的数据类型。我们可以使用引号('或\")来创建字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n",
      "hahaha\n",
      "一二三\n",
      "四五六\n",
      "七八九\n"
     ]
    }
   ],
   "source": [
    "# 字符串用引号创建\n",
    "st1 = 'hello world'\n",
    "st2 = \"hahaha\"\n",
    "st3 = '''一二三\n",
    "四五六\n",
    "七八九'''\n",
    "print(st1)\n",
    "print(st2)\n",
    "print(st3)\n",
    "# ''和\"\"一样 → 单行字符串\n",
    "# ''' ''' 和 \"\"\" \"\"\"一样 → 多行字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "他数学考了 89 分\n"
     ]
    }
   ],
   "source": [
    "# 字符串和数字可以一起print\n",
    "print('他数学考了',89,'分')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "提行\n",
      "提行\n",
      "-----\n",
      "提行\\n提行\\n-----\n"
     ]
    }
   ],
   "source": [
    "# 转义字符 → \\\n",
    "print('提行\\n提行\\n-----')  # \\n：提行\n",
    "print(r'提行\\n提行\\n-----') # r：加上后，\\将不会有转义功能"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C:/Users/Desktop/AI工程师计算机视觉方向_体验课资料/\n",
      "C:\\Users\\Desktop\\AI工程师计算机视觉方向_体验课资料\\\n"
     ]
    }
   ],
   "source": [
    "# 路径的设置\n",
    "dir1 = 'C:/Users/Desktop/AI工程师计算机视觉方向_体验课资料/'\n",
    "dir2 = 'C:\\\\Users\\\\Desktop\\\\AI工程师计算机视觉方向_体验课资料\\\\'  # 这里通过两个\\，转义  \n",
    "#dir3 = 'C:\\Users\\Desktop\\AI工程师计算机视觉方向_体验课资料\\'\n",
    "print(dir1)\n",
    "print(dir2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n",
      "hellohellohellohellohello\n",
      "True False\n"
     ]
    }
   ],
   "source": [
    "# 字符串运算\n",
    "print('hello' + ' world')   # 字符串连接\n",
    "print('hello'*5)   # 重复字符串\n",
    "print('h' in 'hello','h' not in 'hello')   # in、not in 成员运算符\n",
    "# 注意了，目前已经出现五种运算符：赋值运算、数值运算、比较运算、逻辑运算、成员运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "12345 10.29\n",
      "12345 2008.12\n",
      "2000\n",
      "heLLo worLd\n",
      "['小明', '男', '设计师']\n"
     ]
    }
   ],
   "source": [
    "# 常用字符串的函数、方法\n",
    "print(len('12345'))   # len() → 计算长度\n",
    "print(str(12345),str(10.29))     # str() → 将数值型转换成浮点型\n",
    "print(int('12345'),float('2008.12'))   # int()/float() → 将浮点型转换成字符串\n",
    "print(eval('100*20'))    # eval() → 执行字符串中的内容\n",
    "\n",
    "var1 = 'hello world'\n",
    "print(var1.replace('l','L'))  # .replace() → 替换\n",
    "\n",
    "var2 = '小明,男,设计师'\n",
    "print(var2.split(','))   # .split() → 分列，这里结果是一个列表list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "这个班上一共有10人\n",
      "小明这次考了89.936500分\n",
      "小明这次考了89.94分\n",
      "听说城市数据团很6\n",
      "这个班上一共有10人，小明这次考了89.936500分，另外我听说城市数据团很6\n"
     ]
    }
   ],
   "source": [
    "# 格式化字符串\n",
    "# 这里讲其中一种方法：%\n",
    "var1 = 10\n",
    "var2 = 89.9365\n",
    "var3 = '城市数据团'\n",
    "print('这个班上一共有%i人' % var1)   # %i：格式化整数\n",
    "print('小明这次考了%f分' % var2)     # %f：格式化浮点数字\n",
    "print('小明这次考了%.2f分' % var2)   # %.2f：这里表示保留两位小数，会自动四舍五入\n",
    "print('听说%s很6' % var3)            # %s：格式化字符\n",
    "\n",
    "print('这个班上一共有%i人，小明这次考了%f分，另外我听说%s很6' % (var1,var2,var3))\n",
    "# 多次格式化"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4、序列：列表、元组\n",
    "* 序列是Python中最基本的数据结构\n",
    "* 序列中的每个元素都分配一个数字 - 它的位置，也称“索引”，第一个索引是0，第二个索引是1，依此类推。\n",
    "* Python有6个序列的内置类型，但最常见的是列表和元组。\n",
    "* **其实字符串也是序列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n",
      "['a', 'b', 'c', 'd']\n",
      "['abc', 123, 10.2, [1, 2, 3, 4]]\n",
      "这是一个列表: [1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "# 列表用[]创建 → list\n",
    "lst1 = [1,2,3,4,5,6]\n",
    "lst2 = ['a','b','c','d']\n",
    "lst3 = ['abc',123,10.2,[1,2,3,4]]\n",
    "print(lst1)\n",
    "print(lst2)\n",
    "print(lst3)\n",
    "print('这是一个列表:',lst1)\n",
    "# 列表内元素可以是数字、字符串、列表（嵌套列表）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n",
      "[1, 2, 3, 1, 2, 3, 1, 2, 3]\n",
      "False\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# 列表运算\n",
    "print([1,2,3]+[4,5,6])  # 列表组合\n",
    "print([1,2,3]*3)  # 列表重复\n",
    "print(5 in [2,3,4])  # 列表是否存在于表中\n",
    "print(len(lst3))     # 求列表长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 4, 5, 6)\n",
      "('a', 'b', 'c', 'd')\n",
      "('abc', 123, 10.2, (1, 2, 3, 4))\n"
     ]
    }
   ],
   "source": [
    "# 元组用()创建 → tuple\n",
    "# “可变序列”：列表\n",
    "# “不可变序列”：元组、字符串\n",
    "tup1 = (1,2,3,4,5,6)\n",
    "tup2 = 'a','b','c','d'  # 注意，元组不需要括号也可以\n",
    "tup3 = ('abc',123,10.2,(1,2,3,4))\n",
    "print(tup1)\n",
    "print(tup2)\n",
    "print(tup3)"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
